import variables from '@/styles/element-variables.scss'
import defaultSettings from '@/settings'
import {  loginConfigSetting} from '@/api/configs';

const {title, showSettings, tagsView, fixedHeader, sidebarLogo, supportPinyinSearch } = defaultSettings

const state = {
  theme: variables.theme,
  login_title:'',
  title,
  showSettings,
  tagsView,
  fixedHeader,
  sidebarLogo,
  supportPinyinSearch
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    // eslint-disable-next-line no-prototype-builtins
    if (state.hasOwnProperty(key)) {
      state[key] = value
    }
  },
  SET_LOGIN_TITLE: (state,  login_title) => {
    state.login_title = login_title
  }
}

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  },
  configSetting({commit}, data) {
    return new Promise(resolve => {
      loginConfigSetting({type:0}).then((response) => {
        const {data} = response;
        commit('SET_LOGIN_TITLE', data.login_title)

        console.log('login_title')
        console.log(data.login_title)
        resolve();
      }).catch(error => {
        console.log(error);
        resolve(error);
      });
    });
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

